package com.wawei.seeds.me;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

import com.wawei.seeds.R;
import com.wawei.seeds.adapter.SeedsBaseAdapter;
import com.wawei.seeds.adapter.WalnutServiceFragmentAdapter;
import com.wawei.seeds.model.WalnutMainEvent;
import com.wawei.seeds.services.ServiceHandler;
import com.wawei.seeds.services.WalnutMyServiceServiceHandler;

import java.io.Serializable;

/**
 *
 * Created by t27891 on 15/6/22.
 */
public class MeServiceFragment extends MeBaseFragment {

    private WalnutMyServiceServiceHandler serviceServiceHandler;
    private WalnutServiceFragmentAdapter serviceFragmentAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        serviceServiceHandler = new WalnutMyServiceServiceHandler(getActivity());
        serviceFragmentAdapter = new WalnutServiceFragmentAdapter(getActivity());
    }

    @Override
    public Bundle makeConditionBundle(int phase) {
        return null;
    }

    @Override
    public SeedsBaseAdapter<WalnutMainEvent> makeListAdapter() {
        return serviceFragmentAdapter;
    }

    @Override
    public ServiceHandler makeServiceHandler() {
        return serviceServiceHandler;
    }

    @Override
    public void onCreateViewAfterInjection(View view, LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    }

    @Override
    public View onCreateViewBeforeInjection(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //return null for using default layout
        return null;
    }

    @Override
    public void onViewCreatedAfterTitle(View view, Bundle savedInstanceState) {
        progressView.setVisibility(View.VISIBLE);
    }

    @Override
    public String getTitle() {
        return getString(R.string.walnut_me_service);
    }

    @Override
    public Intent makeIntent4ListItemClicked(AdapterView<?> parent, View view, int position, long id, Object itemData) {
        Intent intent = new Intent(getActivity(), MeServiceDetailActivity.class);
        intent.putExtra(MeServiceDetailActivity.ITEM_DATA, (Serializable)itemData);

        return intent;
    }

    @Override
    public void onDestroy() {
        serviceFragmentAdapter.clear();
        serviceFragmentAdapter = null;
        serviceServiceHandler = null;
        super.onDestroy();
    }
}
